import os
import os.path
import tempfile
from unittest import TestCase, mock
from mock_demo.module1 import rm
from mock_demo import module1


class RmTestCase(TestCase):
    def setUp(self):
        self.tmpfilepath = os.path.join(tempfile.gettempdir(), "tmp-testfile")
        with open(self.tmpfilepath, "w") as f:
            f.write("Delete me!")
        
    def test_rm(self):
        self.assertTrue(os.path.isfile(self.tmpfilepath), "file %s not exists" % self.tmpfilepath)
        myos = module1.MyOS()
        rm(myos, self.tmpfilepath)
        self.assertFalse(os.path.isfile(self.tmpfilepath), "Failed to remove the file.")


class RmMockTest(TestCase):
    def test_rm(self):
        mock_os = mock.create_autospec(module1.MyOS)
        mock_os.remove.return_value = "this is mocked"
        print(rm(mock_os, 'xyz'))

